﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>

struct ListNode
{
	int val;
	struct ListNode* next;
};

typedef struct ListNode  LN;

struct ListNode* reverseList(struct ListNode* head)
{
	LN* n1, * n2, * n3;
	n1 = NULL;
	n2 = n3 = head;
	while (n2)
	{
		n3 = n3->next;
		n2->next = n1;
		n1 = n2;
		n2 = n3;
	}
	return n1;
}

int main()
{
	LN l1 = { 1,0 };
	LN l2 = { 2,0 };
	LN l3 = { 3,0 };
	LN l4 = { 4,0 };
	LN l5 = { 5,0 };
	l1.next = &l2;
	l2.next = &l3;
	l3.next = &l4;
	l4.next = &l5;
	l5.next = NULL;
	LN* p = reverseList(&l1);
	//LN* p = reverseList(&l5);
	//LN* p = reverseList(NULL);
	//LN* p = &l1;
	while (p)
	{
		printf("%d ", p->val);
		p = p->next;
	}

	return 0;
}